﻿import idv.ben.gc4flash.axis.*;
import idv.ben.gc4flash.chart.*;
import idv.ben.gc4flash.dataLine.*;
import idv.ben.gc4flash.encode.*;
import idv.ben.gc4flash.fill.*;
import idv.ben.gc4flash.util.*;
/**
* 座標軸。<br>
* 參考 Google Chart API：<a href="http://code.google.com/apis/chart/#multiple_axes_labels" target="_blank">http://code.google.com/apis/chart/#multiple_axes_labels</a><br>
*/
class idv.ben.gc4flash.axis.Axis {
	/**
	* "x" 表示下方座標軸，用於 {@link #Axis()}。
	*/
	public static var AXIS_TYPE_X_BOTTOM:String = "x";
	/**
	* "y" 表示左側座標軸，用於 {@link #Axis()}。
	*/
	public static var AXIS_TYPE_Y_LEFT:String = "y";
	/**
	* "r" 表示右側座標軸，用於 {@link #Axis()}。
	*/
	public static var AXIS_TYPE_Y_RIGHT:String = "r";
	/**
	* "t" 表示上方座標軸，用於 {@link #Axis()}。
	*/
	public static var AXIS_TYPE_X_TOP:String = "t";
	/**
	* 0 表示置中對齊，用於 {@link #setStyle()}。
	*/
	public static var AXIS_ALIGNMENT_CENTER:Number = 0;
	/**
	* -1 表示向左對齊，用於 {@link #setStyle()}。
	*/
	public static var AXIS_ALIGNMENT_LEFT:Number = -1;
	/**
	* 1 表示向右對齊，用於 {@link #setStyle()}。
	*/
	public static var AXIS_ALIGNMENT_RIGHT:Number = 1;
	private var typ:String;
	private var labels:Array;
	private var positions:Array;
	private var ranges:Array;
	private var styles:Array;
	/**
	* 建構子
	* @param typ 座標軸的種類：<br>
	* 		<ul>
	* 		<li>"x" = bottom x-axis</li>
    * 		<li>"t" = top x-axis</li>
    * 		<li>"y" = left y-axis</li>
    * 		<li>"r" = right y-axis</li>
	* 		</ul>
	*/
	function Axis(typ:String) {
		if (typ == AXIS_TYPE_X_BOTTOM || typ == AXIS_TYPE_Y_LEFT || typ == AXIS_TYPE_Y_RIGHT || typ == AXIS_TYPE_X_TOP) {
			this.typ = typ;
			labels = new Array();
			positions = new Array();
			ranges = new Array();
			styles = new Array();
		} else {
			throw new Error("axis type error!!");
		}
	}
	/**
	* 取得座標軸的種類。
	* @return 座標軸的種類：<br>
	* 		<ul>
	* 		<li>"x" = bottom x-axis</li>
    * 		<li>"t" = top x-axis</li>
    * 		<li>"y" = left y-axis</li>
    * 		<li>"r" = right y-axis</li>
	* 		</ul>
	*		<img src="http://chart.apis.google.com/chart?chxt=x,y,r,x&cht=lc&chd=s:cEAELFJHHHKUju9uuXUc&chco=76A4FB&chls=2.0&chs=200x125"><br>
	*		chxt=x,y,r,x
	*/
	public function getTypeChartData():String {
		return typ;
	}
	/**
	* 設定刻度文字<br>
	* @param labels 刻度文字的陣列，[刻度文字1:String, 刻度文字2:String, ..., 刻度文字n:String]
	*/
	public function setLabel(labels:Array):Void {
		this.labels = labels;
	}
	/**
	* 取得刻度文字所組成的 URL 參數字串
	* <br>
	* <img src="http://chart.apis.google.com/chart?chxt=x,y,r,x&chxl=0:|Jan|July|Jan|July|Jan|1:|0|100|2:|A|B|C|3:|2005|2006|2007&cht=lc&chd=s:cEAELFJHHHKUju9uuXUc&chco=76A4FB&chls=2.0&chs=200x125"><br>
	* chxt=x,y,r,x&chxl=0<b>:|Jan|July|Jan|July|Jan</b>|1<b>:|0|100</b>|2<b>:|A|B|C</b>|3<b>:|2005|2006|2007</b><br>
	* <br>
	* <img src="http://chart.apis.google.com/chart?chxt=x,y,r,x&chxl=0:|Jan|July|Jan|July|Jan|2:|A|B|C|3:|2005|2006|2007&cht=lc&chd=s:cEAELFJHHHKUju9uuXUc&chco=76A4FB&chls=2.0&chs=200x125"><br>
	* chxt=x,y,r,x&chxl=0<b>:|Jan|July|Jan|July|Jan</b>|2<b>:|A|B|C</b>|3<b>:|2005|2006|2007</b><br>
	* @return ":|刻度文字1|刻度文字2|...|刻度文字n"
	*/
	public function getLabelChartData():String {
		if (labels.length == 0) {
			return "";
		}
		var chartData:Array = new Array();
		for (var i:Number = 0; i<labels.length; i++) {
			chartData.push(labels[i]);
		}
		return ":|"+chartData.join("|");
	}
	/**
	* 設定刻度位置
	* @param positions 刻度位置的陣列，[刻度位置1:Number, 刻度位置2:Number, ..., 刻度位置n:Number]
	*/
	public function setPosition(positions:Array):Void {
		this.positions = positions;
	}
	/**
	* 取得刻度位置所組成的 URL 參數字串
	* <br>
	* <img src="http://chart.apis.google.com/chart?chxt=x,y,r&chxr=2,0,4&chxl=1:|min|average|max&chxp=1,10,35,75|2,0,1,2,4&cht=lc&chd=s:cEAELFJHHHKUju9uuXUc&chco=76A4FB&chls=2.0&chs=200x125"><br>
	* chxt=x,y,r&chxr=2,0,4&chxl=1:|min|average|max&chxp=1<b>,10,35,75</b>|2<b>,0,1,2,4</b><br>
	* @return ",刻度位置1,刻度位置2,...,刻度位置n"
	*/
	public function getPositionChartData():String {
		if (positions.length == 0) {
			return "";
		}
		var chartData:Array = new Array();
		for (var i:Number = 0; i<positions.length; i++) {
			chartData.push(positions[i]);
		}
		return ","+chartData.join(",");
	}
	/**
	* 設定刻度範圍
	* @param startRanges 最小值
	* @param endRange 最大值
	*/
	public function setRange(startRanges:Number, endRange:Number):Void {
		this.ranges = [startRanges, endRange];
	}
	/**
	* 取得刻度範圍所組成的 URL 參數字串
	* <br>
	* <img src="http://chart.apis.google.com/chart?chxt=x,y,r&chxr=0,100,500|1,0,200|2,1000,0&cht=lc&chd=s:cEAELFJHHHKUju9uuXUc&chco=76A4FB&chls=2.0&chs=200x125"><br>
	* chxt=x,y,r&chxr=0<b>,100,500</b>|1<b>,0,200</b>|2<b>,1000,0</b><br>
	* <br>
	* <img src="http://chart.apis.google.com/chart?chxt=x&chxl=0:|200|300|400&chxp=0,200,300,400&chxr=0,100,500&cht=lc&chd=s:cEAELFJHUc&chco=76A4FB&chls=2.0&chs=200x125"><br>
	* chxt=x&chxl=0:|200|300|400&chxp=0,200,300,400&chxr=0<b>,100,500</b><br>
	* @return ",最小值,最大值"
	*/
	public function getRangeChartData():String {
		if (ranges.length == 0) {
			return "";
		}
		var chartData:Array = new Array();
		for (var i:Number = 0; i<ranges.length; i++) {
			chartData.push(ranges[i]);
		}
		return ","+chartData.join(",");
	}
	/**
	* 設定刻度文字風格
	* @param color 顏色，請參考 Google Chart API：<a href="http://code.google.com/apis/chart/#rgb" target="_blank">http://code.google.com/apis/chart/#rgb</a>
	* @param fontSize optional，字級大小
	* @param alignment optional，對齊方式，x 座標的刻度預設置中，左側 y 座標的刻度預設向右對齊，右側 y 座標的刻度預設向左對齊。若需變更：
	* 		<ul>
	* 		<li>0 = 置中對齊</li>
	* 		<li>-1 = 向左對齊</li>
	* 		<li>1 = 向右對齊</li>
	* 		</ul>
	*/
	public function setStyle(color:String, fontSize:Number, alignment:Number):Void {
		if (fontSize == undefined) {
			styles = [color];
		} else {
			if (alignment == undefined) {
				styles = [color, fontSize];
			} else {
				styles = [color, fontSize, alignment];
			}
		}
	}
	/**
	* 取得刻度文字風格所組成的 URL 參數字串
	* <br>
	* <img src="http://chart.apis.google.com/chart?chxt=x,y,r,x&chxr=2,0,4&chxl=3:|Jan|Feb|Mar|1:|min|average|max&chxp=1,10,35,75&cht=lc&chd=s:cEAELFJHHHKUju9uuXUc&chco=76A4FB&chls=2.0&chs=220x125&chxs=3,0000dd,12"><br>
	* chxt=x,y,r,x&chxr=2,0,4&chxl=3:|Jan|Feb|Mar|1:|min|average|max&chxp=1,10,35,75&chxs=3<b>,0000dd,12</b><br>
	* <br>
	* <img src="http://chart.apis.google.com/chart?chxt=x,x&chxl=1:||Feb|Mar||0:|1st|15th|1st|15th|1st&cht=lc&chd=s:cEAELFJHHHKUju9uuXUc&chco=76A4FB&chls=2.0&chs=200x125&chxs=0,0000dd,10|1,0000dd,12,0"><br>
	* chxt=x,x&chxl=1:||Feb|Mar||0:|1st|15th|1st|15th|1st&chxs=0<b>,0000dd,10</b>|1<b>,0000dd,12,0</b><br>
	* @return ",顏色,字級大小,對齊方式"
	*/
	public function getStyleChartData():String {
		if (styles.length == 0) {
			return "";
		}
		var chartData:Array = new Array();
		for (var i:Number = 0; i<styles.length; i++) {
			chartData.push(styles[i]);
		}
		return ","+chartData.join(",");
	}
}
